package com.jackrain.nea.fc.dl.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLPurInToF4Mapper {

    @SelectProvider(type = ViewDLPurInSql.class, method = "findPurInData")
    List<HashMap> selPurInData(@Param("id") Object[] id);

    @SelectProvider(type = ViewDLPurInSql.class, method = "findPurInItemData")
    List<HashMap> selPurInItemData(@Param("id") Long id);

    @Select("SELECT BILL_NO FROM DL_B_PUR_ORDER WHERE ID=#{id}")
    String selBillNo(Long id);

    class ViewDLPurInSql {

        public String findPurInData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID,BILL_NO,ORDER_BILL_ID,OUT_BILL_ID,CP_C_SUPPLIER_ECODE,CP_C_STORE_ECODE," +
                            "BILL_DATE,REMARK,CREATIONDATE,OWNERENAME,FROM_BILL_NO,BILL_TYPE,MODIFY_BILL_NO," +
                            "MODIFIERNAME,MODIFIERENAME,MODIFIEDDATE,SETTLEMENT_TYPE");
                    FROM("DL_B_PUR_IN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                    WHERE("ACCEPTE_STATUS=2");
                }
            }.toString();
        }

        public String findPurInItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_SKU_ECODE,QTY_IN,PRICE_ACTUAL,DPRICE_LIST,AMT_ACTUAL,PRICE_MGT,AMT_MGT,PRICE_NON_TAX,AMT_NON_TAX");
                    FROM("DL_B_PUR_IN_ITEM");
                    WHERE("DL_B_PUR_IN_ID =" + id);
                }
            }.toString();
        }


    }


}
